#include <vector>
#include <algorithm>
using namespace std;
class Solution
{
public:
    vector<vector<int>> reconstructQueue(vector<vector<int>> &people)
    {
        sort(people.begin(), people.end(), [](vector<int> a, vector<int> b) {
            return a[0] > b[0] || (a[0] == b[0] && a[1] < b[1]);
        });
        vector<vector<int>> ans;
        int size = people.size();
        for (int i = 0; i < size; i++)
        {
            ans.insert(ans.begin() + people[i][1], people[i]);
        }
        return ans;
    }
};
int main(int argc, char const *argv[])
{
    vector<vector<int>> people = {{7, 0}, {4, 4}, {7, 1}, {5, 0}, {6, 1}, {5, 2}};
    Solution s;
    s.reconstructQueue(people);
    return 0;
}
